//导入 mongoose
const mongoose = require('mongoose');
//创建文档的结构对象

// 定义 MachineInfos 模式
const MachineInfosSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true, // 该字段为必填项
    trim: true // 去除字符串前后的空格
  },
  phoneNumber: {
    type: String,
    required: true,
    validate: {
      // 简单的电话号码格式验证，可根据实际需求调整
      validator: function (v) {
        return /^\+?[1-9]\d{1,14}$/.test(v);
      },
      message: props => `${props.value} 不是有效的电话号码！`
    }
  },
  goods: {
    type: String,
    required: true,
    trim: true
  },
  machine_model: {
    type: String,
    required: true,
    trim: true
  },
  machine_failure: {
    type: String,
    required: true,
    trim: true
  },
  creation_time: {
    type: Date,
    default: Date.now // 默认值为当前时间
  }
});

// 创建 MachineInfos 模型，指定集合名称为 'machine_infos'
const MachineInfos = mongoose.model('machine_infos', MachineInfosSchema); //, 'machine_infos'

module.exports = MachineInfos;